package edu.bw.mapper;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;
import po.OrderDetail;
import po.Product;

import java.util.List;

public interface OrderDetailMapper {
    /**
     * 根据订单id查询出订单明细
     * @param orderId
     * @return
     */
    @Results({
            @Result(column = "product_id",property = "productId",id = true),
            @Result(property = "product",javaType = Product.class,column = "product_id",
            one = @One(select = "edu.bw.mapper.ProductMapper.findById",fetchType = FetchType.LAZY))
    })
    @Select("SELECT order_id,product_id,product_num FROM mybatis02.order_detail WHERE order_id= #{orderId} ")
    List<OrderDetail> findOrderDetailByOrderId(int orderId);
}
